package com.client.clovece;
/**
 * This Enumeration defines states, to which a TileButton can get.
 * Most of buttons are in a default state according to their roles in game.
 * Buttons that are occupied by the players are in a BRIGHT state
 * and when they are selected by mouse, they get to SHADED state.
 * 
 * The default states are END (where firure parks at the end), START 
 * (from where it gets to the game), CROSSROAD (first to 
 * stand on and last before END at the same time), GAME 
 * (on which the figures walk), NONPLAYABLE.
 * Owners are EMPTY ( = nobody) and PL1 to PL4. Ownership doesnt
 * change during the game. Dont confuse with an Occupant, who changes
 * according to who stands on the button.
 * */


public enum ButtonStates{
	PL1BRIGHT, PL2BRIGHT, PL3BRIGHT, PL4BRIGHT, 
	PL1DIM, PL2DIM, PL3DIM, PL4DIM,
	PL1START, PL2START, PL3START, PL4START,
	PL1END, PL2END,	PL3END, PL4END, 
	PL1CROSSROAD, PL2CROSSROAD, PL3CROSSROAD, PL4CROSSROAD, 
	PL1INFO, PL2INFO, PL3INFO, PL4INFO,
	GAME, NONPLAYABLE,
	DICE1, DICE2, DICE3, DICE4, DICE5, DICE6, DICEEMPTY,
	EMPTY;
	
	private static final int SIZE = 35;
	
	public static int getSize(){
		return SIZE;
	}
	
	
	/**
	 * These two functions are used to switch from bright to complementary dim
	 * and vice versa when button is clicked. 
	 * */
	public static ButtonStates getDim(ButtonStates xBright){
		switch(xBright){
			case PL1BRIGHT: return PL1DIM;
			case PL2BRIGHT: return PL2DIM;
			case PL3BRIGHT: return PL3DIM;
			case PL4BRIGHT: return PL4DIM;
			default: return EMPTY;
		}
	}
	
	public static ButtonStates getBright(ButtonStates xDim){
		switch(xDim){
			case PL1DIM: return PL1BRIGHT;
			case PL2DIM: return PL2BRIGHT;
			case PL3DIM: return PL3BRIGHT;
			case PL4DIM: return PL4BRIGHT;
			default: return EMPTY;
		}		
	}
	
	/**
	 * Gets state of dice by value thrown on a dice.
	 * */
	public static ButtonStates getDiceByValue(int value){
		if(value < 1 && value > 6) return EMPTY;
		switch(value){
			case 1: return DICE1;
			case 2: return DICE2;
			case 3: return DICE3;
			case 4: return DICE4;
			case 5: return DICE5;
			case 6: return DICE6;
			default: return EMPTY;
		}		
	}
	
	//determines default color(owner of the state)
	public static ButtonStates getOwner(ButtonStates bs){
		/*System.out.println("Button states: ordinal = " + bs.ordinal());*/
		if(bs == ButtonStates.EMPTY) return ButtonStates.EMPTY;
		if(bs.ordinal()%4 == 0) return ButtonStates.PL1BRIGHT;
		if(bs.ordinal()%4 == 1) return ButtonStates.PL2BRIGHT;
		if(bs.ordinal()%4 == 2) return ButtonStates.PL3BRIGHT;
		if(bs.ordinal()%4 == 3) return ButtonStates.PL4BRIGHT;
		return ButtonStates.EMPTY;
	}
	//returns info state that 
	public static ButtonStates toInfo(ButtonStates bs){
		if(bs.ordinal()%4 == 0) return ButtonStates.PL1INFO;
		if(bs.ordinal()%4 == 1) return ButtonStates.PL2INFO;
		if(bs.ordinal()%4 == 2) return ButtonStates.PL3INFO;
		if(bs.ordinal()%4 == 3) return ButtonStates.PL4INFO;
		return ButtonStates.EMPTY;
	}
	
	public static boolean isStart(ButtonStates state){
		return state.ordinal() >= ButtonStates.PL1START.ordinal() && state.ordinal() <= ButtonStates.PL4START.ordinal();
	}
	
	public static boolean isEnd(ButtonStates state){
		return state.ordinal() >= ButtonStates.PL1END.ordinal() && state.ordinal() <= ButtonStates.PL4END.ordinal();
	}
	
	public static boolean isCrossRoad(ButtonStates state){
		return state.ordinal() >= ButtonStates.PL1CROSSROAD.ordinal() && state.ordinal() <= ButtonStates.PL4CROSSROAD.ordinal();
	}
	
	public static boolean isBright(ButtonStates state){
		return state.ordinal() >= ButtonStates.PL1BRIGHT.ordinal() && state.ordinal() <= ButtonStates.PL4BRIGHT.ordinal();
	}
	
	public static boolean isDim(ButtonStates state){
		return state.ordinal() >= ButtonStates.PL1DIM.ordinal() && state.ordinal() <= ButtonStates.PL4DIM.ordinal();
	}
	
	public static boolean isInfo(ButtonStates state){
		return state.ordinal() >= ButtonStates.PL1INFO.ordinal() && state.ordinal() <= ButtonStates.PL4INFO.ordinal();
	}
	
	public static boolean isDice(ButtonStates state){
		return state.ordinal() >= ButtonStates.DICE1.ordinal() && state.ordinal() <= ButtonStates.DICEEMPTY.ordinal();
	}
	
	public static boolean isEmpty(ButtonStates state){
		return state == ButtonStates.EMPTY;
	}
	
	public static boolean isGame(ButtonStates state){
		return state == ButtonStates.GAME;
	}
	
	public static boolean isNonplayable(ButtonStates state){
		return state == ButtonStates.NONPLAYABLE;
	}
		
}
